﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CS_ThicknessDemo
{
    public partial class FrmParse : Form
    {
        private static FrmParse insance;
        public static FrmParse Instance
        {
            get
            {
                if (insance == null)
                {
                    insance = new FrmParse();
                }
                return insance;
            }
        }
        public FrmParse()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            txtSourceContent.Text = "";
            txtFilePath.Text = "";
            OpenFileDialog openFileDialog = new OpenFileDialog();
            if (DialogResult.OK == openFileDialog.ShowDialog())
            {
                //获取选择的文件名
                string fileName = openFileDialog.FileName;
                txtFilePath.Text = fileName;

                using (FileStream fileStream = File.Open(fileName, FileMode.Open))
                {
                    // 初始化一个字节数组，用于存储文件内容
                    byte[] buffer = new byte[fileStream.Length];
                    // 读取文件内容到字节数组
                    int bytesRead = fileStream.Read(buffer, 0, buffer.Length);

                    // 根据需要处理读取的字节数组，例如转换为字符串
                    string content = System.Text.Encoding.UTF8.GetString(buffer, 0, bytesRead);
                    txtSourceContent.Text = content;
                }
            }

        }

        private void cbxCh3_CheckedChanged(object sender, EventArgs e)
        {
            ParseSourceData(txtSourceContent.Text, "3:");
        }

        private List<string> ParseSourceData(string content, string regex)
        {
            string[] splitStr = content.Split(new string[] { regex }, StringSplitOptions.None);
            return splitStr.ToList();
        }

    }
}
